package com.cqc.aiyagril2.module.home;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.cqc.aiyagril2.R;
import com.cqc.aiyagril2.base.BaseActivity;
import com.cqc.aiyagril2.model.CategoryResult;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.loader.ImageLoader;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ${cqc} on 2018/1/12.
 * 主页
 */

public class HomeActivity extends BaseActivity implements HomeContract.IHomeView {


    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.main_viewPager)
    ViewPager mainViewPager;
    @BindView(R.id.navView)
    NavigationView navView;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_home;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        banner.setIndicatorGravity(BannerConfig.RIGHT);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);


    }

    @Override
    protected void initData() {
        HomePresenter presenter = new HomePresenter(this, disposable);
        presenter.getHomeBanners();
    }

    @Override
    public void getHomeBannersSuccess(CategoryResult categoryResult) {
        List<CategoryResult.ResultsBean> bannerList = categoryResult.results;
        banner.setImages(bannerList);
        banner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                CategoryResult.ResultsBean info = (CategoryResult.ResultsBean) path;
                Glide.with(context).load(info.url).into(imageView);
            }
        });
        banner.start();
    }

    @Override
    public void getHomeBannersFail(String error) {
        showToast(error);
    }
}
